package com.it.dbflow;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;

import com.raizlabs.android.dbflow.config.FlowManager;
import com.raizlabs.android.dbflow.sql.language.SQLite;
import com.raizlabs.android.dbflow.structure.ModelAdapter;
import com.raizlabs.android.dbflow.structure.database.AndroidDatabase;
import com.raizlabs.android.dbflow.structure.database.transaction.QueryTransaction;

import java.util.List;
import java.util.UUID;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        User user = new User();
        user.id = UUID.randomUUID();
        user.name = "Andrew Grosner";
        user.age = 27;

        ModelAdapter<User> adapter = FlowManager.getModelAdapter(User.class);
        adapter.save(user);
        adapter.getTableName();
        SQLite.select().from(User.class)
                .where(User_Table.age.greaterThan(18))
                .async().queryListResultCallback(new QueryTransaction.QueryResultListCallback<User>() {
                    @Override
                    public void onListQueryResult(QueryTransaction transaction, @NonNull List<User> tResult) {
                        System.out.println("tResult______"+tResult.size());

                    }
                }).execute();
//        SQLite.select().from(User.class).querySingle();
//        SQLite.select().from(User.class).query(;);
        SQLite.select().from(User.class);
        ((AndroidDatabase)(AppDatabase.getDatabase())).execSQL("update  user set age=0   where name='Andrew Grosner'");
    }
}
